package com.jimikongjian.service.dao.impl;

import com.jimikongjian.dao.IRoomFollower;
import com.jimikongjian.models.RoomFollower;
import com.jimikongjian.models.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by fuxiuyang on 17/3/4.
 */
@Service("iRoomFollowerImpl")
public class IRoomFollowerImpl implements IRoomFollower {

    @Autowired
//    @Qualifier("roomFollowerMapper")
    private IRoomFollower iRoomFollower;

    /**
     * 通过自身的id号，获取某一确定的空间关注的信息
     *
     * @param id
     * @return List<RoomFollower>
     */
    public List<RoomFollower> getRoomFollowerListById(int id) {
        if (id > 0){
            return iRoomFollower.getRoomFollowerListById(id);
        }
        return null;
    }

    /**
     * 通过自身的id号，获取某一确定的空间关注的信息
     *
     * @param id
     * @return RoomFollower
     */
    public RoomFollower getRoomFollowerById(int id) {
        if (id > 0){
            List<RoomFollower> roomFollowerList = getRoomFollowerListById(id);
            if (roomFollowerList.size() > 0){
                return roomFollowerList.get(0);
            }
        }
        return null;
    }

    /**
     * 获取用户关注的所有的空间
     *
     * @param userId
     * @return List<RoomFollower>
     */
    public List<RoomFollower> getRoomFollowerListByUserId(int userId) {
        if (userId > 0){
            return iRoomFollower.getRoomFollowerListByUserId(userId);
        }
        return null;
    }

    /**
     * 获取关注该空间的所有的用户
     *
     * @param roomId
     * @return List<RoomFollower>
     */
    public List<UserInfo> getRoomFollowerListByRoomId(int roomId, int start, int length) {
        if (roomId > 0 && start>= 0 && length > 0){
            return iRoomFollower.getRoomFollowerListByRoomId(roomId, start, length);
        }
        return null;
    }

    /**
     * 获取该空间是否具有该用户
     *
     * @param roomId
     * @param userId
     * @return List<RoomFollower>
     */
    public List<RoomFollower> getRoomFollowerListByUserIdAndRoomId(int userId, int roomId) {
        if (roomId > 0 && userId > 0){
            return iRoomFollower.getRoomFollowerListByUserIdAndRoomId(userId, roomId);
        }
        return null;
    }

    /**
     * 判断该空间是否有该用户
     *
     * @param userId
     * @param roomId
     * @return List<RoomFollower>
     */
    @Override
    public boolean hasUser(int userId, int roomId) {
        List list = getRoomFollowerListByUserIdAndRoomId(userId, roomId);
        if (list != null && list.size() > 0){
            return true;
        }
        return false;
    }

    /**
     * 创建一条新的空间关注
     *
     * @param roomFollower
     */
    public void insertRoomFollower(RoomFollower roomFollower) {
        if (roomFollower.getUserId() > 0
                && roomFollower.getRoomId() > 0){
            iRoomFollower.insertRoomFollower(roomFollower);
        }
    }

    /**
     * 更新某一条空间关注的信息
     *
     * @param roomFollower
     */
    public void updateRoomFollower(RoomFollower roomFollower) {
//        不允许更新，有什么不满意的，直接删除
    }

    /**
     * 删除某一条空间关注的信息
     *
     * @param roomFollower
     */
    public void deleteRoomFollower(RoomFollower roomFollower) {
        if (roomFollower.getUserId() > 0
                && roomFollower.getRoomId() > 0){
            iRoomFollower.deleteRoomFollower(roomFollower);
        }
    }
}
